from fastapi import FastAPI, APIRouter, File, UploadFile
from typing import List

app05 = APIRouter()


@app05.post("/files/")
async def create_file(file: bytes = File()):
    print("file:", file)
    return {
        "file_size": len(file)
    }


@app05.post("/multiFiles")
async def create_files(files: List[bytes] = File()):
    return {
        "file_sizes": [len(file) for file in files]
    }


@app05.post("/uploadFile/")
async def create_upload_file(file: UploadFile):
    with open(f"{file.filename}", 'wb') as f:
        for chunk in iter(lambda: file.file.read(1024), b''):
            f.write(chunk)

    return {"filename": file.filename}


@app05.post("/multiUploadFiles/")
async def create_upload_files(files: List[UploadFile]):
    return {"filenames": [file.filename for file in files]}
